home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / include / scribus-ng / style.h < prev    next >
Encoding:
C/C++ Source or Header  |  2009-03-19  |  5.4 KB  |  157 lines

  1. /*
  2.  For general Scribus (>=1.3.2) copyright and licensing information please refer
  3.  to the COPYING file provided with the program. Following this notice may exist
  4.  a copyright and/or license notice that predates the release of Scribus 1.3.2
  5.  for which a new license (GPL+exception) is in place.
  6.  */
  7. /***************************************************************************
  8. *                                                                         *
  9. *   This program is free software; you can redistribute it and/or modify  *
  10. *   it under the terms of the GNU General Public License as published by  *
  11. *   the Free Software Foundation; either version 2 of the License, or     *
  12. *   (at your option) any later version.                                   *
  13. *                                                                         *
  14. ***************************************************************************/
  15.  
  16.  
  17. #ifndef STYLE_H
  18. #define STYLE_H
  19.  
  20. #include <cassert>
  21. #include <QString>
  22. #include "scfonts.h"
  23. #include "scribusapi.h"
  24. #include "sccolor.h"
  25. #include "styles/stylecontext.h"
  26. #include "desaxe/saxio.h"
  27.  
  28.  
  29. /**
  30.  *  This is the base class for all style-like objects: CharStyles, 
  31.  *  ParagraphStyles, LineStyles, FrameStyles, CellStyles,
  32.  *  FlowStyles,...
  33.  *  It provides a name and an inheritance mechanism which uses a Stylecontext.
  34.  *  Before any attribute is queried, you have to call validate(), which checks
  35.  *  the stored m_contextversion against the StyleContext's version and updates all
  36.  *  attributes if they are different.
  37.  */
  38. class SCRIBUS_API Style : public SaxIO {
  39. protected:
  40.     bool m_isDefaultStyle;
  41.     QString m_name;
  42.     const StyleContext* m_context;
  43.     int m_contextversion;
  44.     QString m_parent;
  45.     QString m_shortcut;
  46. public:
  47. //    static const short NOVALUE = -16000;
  48.  
  49.     Style(): m_isDefaultStyle(false), m_name(""), m_context(NULL), m_contextversion(-1), m_parent(""), m_shortcut() {}
  50.  
  51.     Style(StyleContext* b, QString n): m_isDefaultStyle(false), m_name(n), m_context(b), m_contextversion(-1), m_parent(""), m_shortcut() {}
  52.     
  53.     Style& operator=(const Style& o) 
  54.     { //assert(typeinfo() == o.typeinfo()); 
  55.         m_isDefaultStyle = o.m_isDefaultStyle;
  56.         m_name = o.m_name;
  57. //        m_context = o.m_context; 
  58.         m_contextversion = -1; 
  59.         m_parent = o.m_parent;
  60.         m_shortcut = o.m_shortcut;
  61.         return *this;
  62.     }
  63.     
  64.     Style(const Style& o) : SaxIO(), m_isDefaultStyle(o.m_isDefaultStyle),m_name(o.m_name), 
  65.         m_context(o.m_context), m_contextversion(o.m_contextversion), m_parent(o.m_parent), m_shortcut(o.m_shortcut) {} 
  66.     
  67.     virtual ~Style()                 {}
  68.  
  69.     
  70.     // this is an abstract class, so:
  71.     // static const Xml_string saxxDefaultElem; 
  72.     template<class SUBSTYLE>
  73.         static void  desaxeRules(const Xml_string& prefixPattern, desaxe::Digester& ruleset, Xml_string elemtag);
  74.     
  75.     void saxxAttributes(Xml_attr& attr) const;
  76.     //virtual void saxx(SaxHandler& handler, const Xml_string& elemtag) const;
  77.     //virtual void saxx(SaxHandler& handler)                     const { saxx(handler, saxxDefaultElem); }
  78.     
  79.     void setDefaultStyle(bool ids);
  80.     bool isDefaultStyle() const      { return m_isDefaultStyle; }
  81.     
  82.     QString name() const             { return m_name; }
  83.     void setName(const QString& n)   { m_name = n.isEmpty() ? "" : n; }
  84.     bool hasName() const             { return ! m_name.isEmpty(); }
  85.  
  86.     virtual QString displayName() const = 0;/*{     
  87.         if ( hasName() || !hasParent() || !m_context)
  88.             return name();
  89.         //    else if ( inheritsAll() )
  90.         //        return parent()->displayName();
  91.         else 
  92.             return parentStyle()->displayName();
  93.     }*/
  94.     
  95.     QString parent() const           { return m_parent; }
  96.     void setParent(const QString& p);
  97.     bool hasParent() const           { return ! m_parent.isEmpty(); }
  98.     const Style* parentStyle() const;
  99.     
  100.     static const QString INHERIT_PARENT;
  101.     
  102.     virtual void setContext(const StyleContext* context);
  103.     const StyleContext* context() const        { return m_context; }
  104.     
  105.     /**
  106.         sets a new StyleContext if b is not NULL and then uses the StyleContext
  107.         to set all inherited attributes to their valid value.
  108.      */
  109.     virtual void update(const StyleContext* b = NULL);
  110.     
  111.     /**
  112.         Checks if this Style needs an update
  113.      */
  114.     void validate() const;
  115.  
  116.     QString shortcut() const { return m_shortcut; }
  117.     void setShortcut(const QString &shortcut) { m_shortcut = shortcut; }
  118.  
  119.     /**
  120.         returns true if both Styles are of the same type, inherit the same attributes,
  121.         have the same parent, and agree on all attributes which are not inherited.
  122.         The StyleContext, the name and any inherited attrinutes may be different.
  123.      */
  124.     virtual bool equiv(const Style& other) const = 0;
  125.     /**
  126.         returns true if both Styles are equivalent and have the same name.
  127.         Since the context is not tested, this does *not* ensure they will return
  128.         the same values for all attributes.
  129.      */
  130.     virtual bool operator==(const Style& other) const { return name() == other.name() && equiv(other); }
  131.     virtual bool operator!=(const Style& other) const { return ! ( (*this) == other ); }
  132.  
  133.     /**
  134.         resets all attributes to their defaults and makes them inherited.
  135.         name and parent are not affected.
  136.      */
  137.     virtual void erase() = 0;
  138.     /**
  139.         if other has a parent, replace this parent with the other ones
  140.      */
  141.     void applyStyle(const Style& other) { 
  142.         if (other.hasParent())
  143.             setParent( other.parent() == INHERIT_PARENT? "" :other.parent());
  144.         m_contextversion = -1;
  145.     }
  146.     /** 
  147.         if other has the same parent, remove this parent 
  148.      */
  149.     void eraseStyle(const Style& other) {
  150.         if (other.parent() == parent())
  151.             setParent("");
  152.         m_contextversion = -1;
  153.     }
  154. };
  155.  
  156. #endif
  157.